DOUBLE PRECISION function soal_2_dif_dy(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	
	soal_2_dif_dy = -0.5 * y
END

DOUBLE PRECISION function soal_2_dif_dz(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	
	soal_2_dif_dz = 4 -0.3 * z - 0.1 * y
END


subroutine hitung_soal2_dif(metode,x,h)
!metode 1-5
	implicit none
	integer*2 metode
	double precision x,h
	double precision soal_2_dif_dy, soal_2_dif_dz
	external soal_2_dif_dy, soal_2_dif_dz
	external runge_kutta_param3,runge_kutta_param4
	external adamsmuolton_param3,y_Heun_param3,y_Euler_param3
	double precision x0,y0,z0
	double precision y_hasil, z_hasil
	
	x0 = 0
	y0 = 4
	z0 = 6
	select case (metode)
		case (1)
			print*,"Metode Euler"
			call y_Euler_param3(x0,y0,z0,x,h,soal_2_dif_dy,soal_2_dif_dz,y_hasil,z_hasil)			
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
			print*,"Nilai z = ",z_hasil
		case (2)
			print*,"Metode Heun"
			call y_Heun_param3(x0,y0,z0,x,h,soal_2_dif_dy,soal_2_dif_dz,y_hasil,z_hasil)
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
			print*,"Nilai z = ",z_hasil
		case (3)
			print*,"Metode Runge Kutta Orde 3"
			call runge_kutta_param3(x0,y0,z0,x,h,soal_2_dif_dy,soal_2_dif_dz,y_hasil,z_hasil)
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
			print*,"Nilai z = ",z_hasil
		case (4)
			print*,"Metode Runge Kutta Orde 4"
			call runge_kutta_param4(x0,y0,z0,x,h,soal_2_dif_dy,soal_2_dif_dz,y_hasil,z_hasil)
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
			print*,"Nilai z = ",z_hasil
		case (5)
			print*,"Metode Adams Bashforth Muolton"
			call adamsmuolton_param3(x0,y0,z0,x,h,soal_2_dif_dy,soal_2_dif_dz,y_hasil,z_hasil)
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
			print*,"Nilai z = ",z_hasil
	end select

end

DOUBLE PRECISION function soal_1_dif_rekayasa_dy(x,y,z)
	IMPLICIT NONE
	double precision x,y,z
	
	soal_1_dif_rekayasa_dy = z
END

DOUBLE PRECISION function soal_1_dif_rekayasa_dz(x,y,z)
	IMPLICIT NONE
	double precision x,y,z,e
	common /soal_1_dif_rekayasa_global/ e
	
	soal_1_dif_rekayasa_dz = e*y**2 - y
END

subroutine hitung_soal1_dif_rekayasa(metode,x)
!metode 1-5
	implicit none
	integer*2 metode, i
	double precision x,h
	double precision soal_1_dif_rekayasa_dy, soal_1_dif_rekayasa_dz,e
	external soal_1_dif_rekayasa_dy, soal_1_dif_rekayasa_dz
	external runge_kutta_param3,runge_kutta_param4
	external adamsmuolton_param3,y_Heun_param3,y_Euler_param3
	double precision x0,y0,z0
	double precision y_hasil, z_hasil
	common /soal_1_dif_rekayasa_global/ e
	
	h = 0.5
	x0 = 0
	y0 = 1
	z0 = 0
	
	e = 0.001d0
	select case (metode)
		case (1)
			print*,"Metode Euler"
		case (2)
			print*,"Metode Heun"
		case (3)
			print*,"Metode Runge Kutta Orde 3"
		case (4)
			print*,"Metode Runge Kutta Orde 4"
		case (5)
			print*,"Metode Adams Bashforth Muolton"
	end select
	
	print*,"Untuk x = ",x
	do i = 1,4
		e = e*10
		select case (metode)
			case (1)
				call y_Euler_param3(x0,y0,z0,x,h,soal_1_dif_rekayasa_dy,soal_1_dif_rekayasa_dz,y_hasil,z_hasil)			
			case (2)
				call y_Heun_param3(x0,y0,z0,x,h,soal_1_dif_rekayasa_dy,soal_1_dif_rekayasa_dz,y_hasil,z_hasil)
			case (3)
				call runge_kutta_param3(x0,y0,z0,x,h,soal_1_dif_rekayasa_dy,soal_1_dif_rekayasa_dz,y_hasil,z_hasil)
			case (4)
				call runge_kutta_param4(x0,y0,z0,x,h,soal_1_dif_rekayasa_dy,soal_1_dif_rekayasa_dz,y_hasil,z_hasil)
			case (5)
				call adamsmuolton_param3(x0,y0,z0,x,h,soal_1_dif_rekayasa_dy,soal_1_dif_rekayasa_dz,y_hasil,z_hasil)
		end select
		print*,"Untuk e = ",e
		print*,"Nilai y = ",y_hasil
		print*,"Nilai z = ",z_hasil
	end do
end


DOUBLE PRECISION function soal_4_dif_rekayasa_dy(x)
	IMPLICIT NONE
	double precision x
	
	soal_4_dif_rekayasa_dy = 0.02 * x - 0.00004 * x**2

END

subroutine hitung_soal4_dif_rekayasa(metode)
!metode 1-5
	implicit none
	integer*2 metode
	double precision x,h
	double precision soal_2_dif_dy, soal_2_dif_dz
	external soal_4_dif_rekayasa_dy
	external y_Euler,y_Heun,RUNGE_KUTTA_ORDE_3,RUNGE_KUTTA_ORDE_4
	external ADAM_BASHFORTH_MOULTON
	double precision x0,y0
	double precision y_hasil
	
	x = 2000
	h = 10.0
	x0 = 1900
	y0 = 76.4 * 10**6
	
	select case (metode)
		case (1)
			print*,"Metode Euler"
			call y_Euler(x0,y0,x,h,y_hasil, soal_4_dif_rekayasa_dy)			
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
		case (2)
			print*,"Metode Heun"
			call y_Heun(x0,y0,x,h,y_hasil, soal_4_dif_rekayasa_dy)
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
		case (3)
			print*,"Metode Runge Kutta Orde 3"
			call RUNGE_KUTTA_ORDE_3(x0,y0,x,h,y_hasil, soal_4_dif_rekayasa_dy)
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
		case (4)
			print*,"Metode Runge Kutta Orde 4"
			call RUNGE_KUTTA_ORDE_4(x0,y0,x,h,y_hasil, soal_4_dif_rekayasa_dy)
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
		case (5)
			print*,"Metode Adams Bashforth Muolton"
			call ADAM_BASHFORTH_MOULTON(x0,y0,x,h,y_hasil, soal_4_dif_rekayasa_dy)
			print*,"Untuk x = ",x
			print*,"Nilai y = ",y_hasil
	end select

end
